/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.shop.web.controllers;

import java.io.IOException;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.shop.domain.Customer;
import org.shop.service.InventoryService;
import org.shop.utils.InstanceUtils;
import org.shop.web.utils.RootController;

/**
 *
 * @author Vinnu
 */
public class BalanceController extends RootController {

    private static Logger log = Logger.getLogger(BalanceController.class);

    @Override
    protected void doWork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String customerName = request.getParameter("customerName");
        long mobile = Long.valueOf(request.getParameter("mobile"));
        log.debug(customerName + mobile);

        InstanceUtils utils = new InstanceUtils();
        InventoryService service = utils.getService();
        Customer customer = service.findByCustomer(customerName, mobile);
        if (customer == null) {
            return;
        } else {
            Map<String, Object> balanceMap = service.getBalanceDetails(customer.getCustomer_Id());
            log.info("Balance Map:-" + balanceMap);
            request.setAttribute("MapDetails", balanceMap);
            request.getRequestDispatcher("/balance.jsp").forward(request, response);

        }

    }
}
